package com.rlz.framemm.viewmodel

import android.app.Application
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Transformations
import androidx.lifecycle.liveData
import com.rlz.base.base.BaseViewModel
import com.rlz.base.util.ToastUtils
import com.rlz.framemm.model.TestModel

/**
 * Created by RLZ
 * on 2021/10/20
 *
 */
class TestViewModel constructor(app: Application) : BaseViewModel<TestModel>(app) {

    private var bannerEvent = MutableLiveData<Any>()


    val bannerData = Transformations.switchMap(bannerEvent) {
        liveData {
            val bannerData = try {
                Result.success(mRepository.getBanners())
            } catch (e: Exception) {
                Result.failure(e)
            }
            emit(bannerData)
        }
    }


    fun onBannerRefresh() {
        bannerEvent.value = bannerEvent.value
    }
}